
package it.enrollement;


import java.util.Random;
import jpair.api.Field;
import jpair.api.FieldElement;
import jpair.api.Pairing;
import jpair.pairing.BigInt;
import jpair.pairing.Fp;
import jpair.pairing.Point;
import jpair.pairing.Predefined;
/**
 * The KGC realizes the setting of its crypto-parameters. 
 * 
 * @author Francesco Rossi
 * @version 0.1
 * 
 */

public class Setup {
     /** Pairing e; Default Pairing  */
        Pairing e;
         
        Random rnd;
       /** BigInt s; KCG Private key */
        BigInt s; 
           /** BigInt r; Blinding Factor */
        BigInt r;
         /** Point Ppub; KCG Public key */
        Point Ppub;
       /** Point P ; Curve Generator P */ 
        Point P ; 
       Point W;
         /** FieldElement epp;  Pre-Computed Pairing for ZSS */
       FieldElement epp;
       
       
       /** Point P ; Curve Generator P */ 
        Point P2 ; 
        
          /** Point Ppub 1; KCG Public key on G2 */
        Point Ppub2;
       
    public Setup(Pairing pairing) {
        
         e = pairing;
    }

    public void Init(System_Param param) {

    
   

        
       

        // Random value
        rnd = new Random();

        // Group Generator P
    //    P = e.getCurve().getBasePoint(rnd, e.getGroupOrder(), e.getCofactor());
 
	//	FieldElement y= new BigInt("1112431795523955379832521079793356877296027600169",10);
        
 P = e.RandomPointInG1(new Random());
    
//P = e.RandomPointInG1(rnd);
        // Private Master key s
        s = new BigInt(e.getGroupOrder().bitLength(), rnd);

        // Public Master key Ppub 
        Ppub = e.getCurve().multiply(P, s);


        // Precomputed pairing
        epp = e.compute(P, P);

 

        // Blinding Factor
        r = new BigInt(e.getCurve().getField().getOrder().bitLength(), rnd);
        
        
        // Public Value
        W = e.getCurve().multiply(P, r);
        
     
        //////////////////////////////////////////////////////

        // Random value
        rnd = new Random();
        
        
        // Group Generator P2
 P2 = e.RandomPointInG2(new Random());
        
         // Public Master key Ppub 
        Ppub2 = e.getCurve2().multiply(P2, s);
        
        
           param.setR(r);
        param.setW(W);
        param.setE(e);
        param.setRnd(rnd);

        param.setP(P);

        param.setS(s);

        param.setPpub(Ppub);

        param.setEpp(epp);
param.setP2(P2);
param.setPpub2(Ppub2);
        

    }
}
